<?php
// Script from http://www.coursesweb.net/ajax/

require "php/akses.php";
if (!isset($_SESSION)) {session_start();}
connect();

$max_size = 100000;			// maxim size for image file, in KiloBytes

/** Uploading the image **/
$filename = $_SESSION['username'].".jpg";

echo $_SESSION['username'];

if (isset ($_FILES['myfile'])) {
	if ($_FILES["myfile"]["error"] > 0) {
			echo "Return Code: " . $_FILES["myfile"]["error"] . "<br />";
		} else {
			$avatarfolder = "images/avatar/";
			$savefilename = $_SESSION['username']."."."jpg";
			move_uploaded_file($_FILES["myfile"]["tmp_name"],
			$avatarfolder . $savefilename);
			$rezultat = '<img src="'.$avatarfolder . $savefilename.'" />';
		}
	if ($_SESSION['avatar_path']!=$avatarfolder . $savefilename) {
		$_SESSION['avatar_path']=$avatarfolder . $savefilename;
		updateAvatar($_SESSION['userid'], $avatarfolder . $savefilename);
	}
	$rezultat = urlencode($rezultat);
	
	echo '<body onload="parent.doneloading(\''.$rezultat.'\')"></body>';
}

?>